package 第二轮工作.沈阳航空航天大学;

import com.alibaba.excel.EasyExcel;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import 第二轮工作.西安邮电大学.XAuBean;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SYHu {
    public static void main(String[] args) throws IOException {
        SYHuBean syHuBean = null;
        List<SYHuBean> syHuBeans = new ArrayList<>();
        String Url = "https://jd.sau.edu.cn/xygk/szdw.htm";
        String c_url;
        int i = 1;
        Connection connect = Jsoup.connect(Url);
        Document post = connect.post();
        for (Element pNo : post.getElementsByClass("p_no")) {
            for (Element element : pNo.getElementsByTag("a")) {
                c_url = element.attr("href");
                String url = "https://jd.sau.edu.cn/xygk/" + c_url;
                Connection connect1 = Jsoup.connect(url);
                System.out.println(i++);
                Document post1 = connect1.post();
                for (Element elementsByClass : post1.getElementsByClass("text-list")) {
                    for (Element li : elementsByClass.getElementsByTag("li")) {
                        for (Element a : li.getElementsByTag("a")) {
                            syHuBean = new SYHuBean();
                            System.out.println(a.text());
                            syHuBean.setT_name(a.text());
//                            System.out.println(a.attr("href"));
                            String substring = a.attr("href").substring(5, a.attr("href").length());
                            Connection connect2 = Jsoup.connect("https://jd.sau.edu.cn" + substring);
                            Document post2 = connect2.post();
                            for (Element vNewsContent : post2.getElementsByClass("v_news_content")) {
//                                System.out.println(vNewsContent.text());
                                syHuBean.setInfo(vNewsContent.text());
                                syHuBeans.add(syHuBean);

                            }
                        }

                    }

                }

            }

        }
        EasyExcel.write("src/SYu.xlsx", SYHuBean.class).sheet("user").doWrite(syHuBeans);


    }
}
